package com.sann.oss.controller;

import com.sann.common.utils.R;
import com.sann.oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/eduoss/fileoss/")
@CrossOrigin
public class OssController {

    @Autowired
    private OssService ossService;

    /**
     * 上传头像到阿里的OSS。
     * 1、MultipartFile 就是接收到的上传文件对象
     * 2、返回上传到OSS的地址
     */
    @PostMapping(value = "avatarUpload")
    public R avatarUpload(MultipartFile file){
        String url = ossService.uploadAvatar(file);
        return R.ok().data("url", url);
    }
}
